package org.wmq.javafxmapcollectioncs.controller;

import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.DatePicker;
import javafx.scene.control.TextField;
import org.wmq.javafxmapcollectioncs.God;
import org.wmq.javafxmapcollectioncs.model.Entity.MapEntity;
import org.wmq.javafxmapcollectioncs.model.common.MyList;

public class FindViewController {

    @FXML
    private TextField nameText;

    @FXML
    private TextField mapTypeText;

    @FXML
    private TextField mediumText;

    @FXML
    private DatePicker publicationTimePicker;

    @FXML
    private DatePicker collectionTimePicker;

    @FXML
    private Button findButton;

    @FXML
    private void initialize() {
        // 初始化逻辑可以放在这里
    }

    @FXML
    private void findMap() {
        // 实现查找地图的逻辑
        System.out.println("Finding a map");
        // 获取输入的值
        String name = nameText.getText();
        String mapType = mapTypeText.getText();
        String medium = mediumText.getText();
        // 获取日期选择器的值
        java.time.LocalDate publicationTime = publicationTimePicker.getValue();
        java.time.LocalDate collectionTime = collectionTimePicker.getValue();

        // 这里可以添加将这些值用于查找地图的逻辑
        MyList<MapEntity> mapEntityList = God.getGod().getMapEntityList();
        mapEntityList.moveToHead();
        for(MapEntity cur = mapEntityList.getCurrentData();cur != mapEntityList.getLastData();cur = mapEntityList.getCurrentData()){
            if (name != null && !name.isEmpty() && !name.equals(cur.getName())) {
                mapEntityList.moveToNext();
                continue;
            }
            if (mapType != null && !mapType.isEmpty() && !mapType.equals(cur.getMapType())) {
                mapEntityList.moveToNext();
                continue;
            }
            if (medium != null && !medium.isEmpty() && !medium.equals(cur.getMedium())) {
                mapEntityList.moveToNext();
                continue;
            }
            if (publicationTime != null && !publicationTime.equals(cur.getPublicationTime())) {
                mapEntityList.moveToNext();
                continue;
            }
            if (collectionTime != null && !collectionTime.equals(cur.getCollectionTime())) {
                mapEntityList.moveToNext();
                continue;
            }
            break;
        }

    }
}